home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 511 / turing / turing.asc < prev    next >
Encoding:
Text File  |  1991-02-13  |  11.8 KB  |  414 lines

  1.                       Turing Machine Simulation
  2.  
  3.                                by
  4.  
  5.                    Robert and Alexander Feinman  
  6.  
  7.  
  8.  
  9.                           Introduction
  10.   
  11.      This program simulates a Turing Machine, a theoretical type 
  12.  
  13. of computer first described by the mathematican Alan Turing in 
  14.  
  15. the 1930's. Turing invented this model to study basic problems in 
  16.  
  17. a branch of mathematics known as predicate calculus. His intent 
  18.  
  19. was to design a machine that could represent any algorithm in a 
  20.  
  21. series of finite states (program steps). While this model leads 
  22.  
  23. to some interesting studies in mathematics it is also possible to 
  24.  
  25. consider the Turing machine as a a prototype of a digital 
  26.  
  27. computer.
  28.  
  29.      Basically a Turing machine can be represented by a 
  30.  
  31. mechanical device. Imagine a computer consisting of a long tape 
  32.  
  33. on which can be placed a series of symbols drawn from a list. For 
  34.  
  35. our purposes it is sufficient to assume only two symbols, zero 
  36.  
  37. and one. Above this tape is a read/write head. First, this head 
  38.  
  39. reads the mark on the tape at the current position. The value of 
  40.  
  41. the mark causes the machine to take an action determined by the 
  42.  
  43. state of its control program. Second, a new symbol is written to 
  44.  
  45. the tape on the current position. Third, The tape moves one space 
  46.  
  47. either right or left. Finally, the control program jumps to a new 
  48.  
  49. step. The control program has a series of these statements 
  50.  
  51. similar to the lines of a conventional programming language. Each 
  52.  
  53. of these statements is called one of the possible states of the 
  54.  
  55. machine. The programming language consists of only four 
  56.  
  57. components: the step number, the symbol to write, the direction 
  58.  
  59. to move, and the number of the next step to execute. Each step 
  60.  
  61. has two parts: the first specifies the action to take if the tape 
  62.  
  63. contains a zero and the other the action to take if it contains a 
  64.  
  65. one. Thus a typical step might be represented as follows:
  66.  
  67.  
  68. Step x:   If tape = 0:
  69.  
  70.                Write 1, Move tape left, Jump to step n.
  71.   
  72.           Else
  73.   
  74.                Write 0, Move tape right, Jump to step m.
  75.   
  76.  
  77.      Turing showed that this simple set of instructions can be 
  78.  
  79. used to generate any actions that a large-scale computer can 
  80.  
  81. perform. Over the past few years there have been a number of 
  82.  
  83. articles on Turing Machines giving sample implementations for a 
  84.  
  85. variety of microcomputers. I decided to implement a simulation 
  86.  
  87. for the Atari ST which makes use of the graphic abilities of the 
  88.  
  89. computer. The creation of the Degas background was done by my son 
  90.  
  91. Alex, who also helped with some of the final testing and debugging.
  92.  
  93. The program was written in GFA Basic and compiled. It runs in low
  94.  
  95. resolution only. I used a trick to incorporate the Degas picture
  96.  
  97. into the actual executable file, thus avoiding the need for data
  98.  
  99. statements or a separate picture file.
  100.  
  101.      Questions and comments can be directed to:
  102.  
  103. Compuserve: 71350,3607
  104.  
  105. Genie: RFEINMAN
  106.  
  107. Internet: rdf@pinet.aip.org
  108.  
  109. Bitnet: rdf@aip.bitnet
  110.  
  111.  
  112.  
  113.                          Program Usage
  114.  
  115.  
  116.      The program displays a whimsical screen representing a 
  117.  
  118. factory with a conveyor belt near the bottom of the screen acting 
  119.  
  120. as the tape. Referring to the figure we see the read/write head 
  121.  
  122. shown by an arrow pointing to the tape. In addition there are 
  123.  
  124. four boxes in the upper left corner connected by pipes with 
  125.  
  126. arrows in them. Within these boxes are groups of two buttons used 
  127.  
  128. to program the computer. This group is used to enter a program 
  129.  
  130. step. Below this is a selector box with a handle labeled MODE. 
  131.  
  132. Clicking in this box allows the user to cycle through the various 
  133.  
  134. functions that the simulation permits. In the INPUT mode enter a 
  135.  
  136. program step by clicking on one button in the MOVE group, one 
  137.  
  138. button in the WRITE group and then click on the up/down arrows in 
  139.  
  140. the JUMP group until the desired number appears in the STEP 
  141.  
  142. window. At this point click in the STEP window to select the 
  143.  
  144. state to jump to. The sequence is ended by pressing DO.
  145.  
  146.      The program automatically numbers each statement as it is 
  147.  
  148. entered and shifts from the 'read a zero' case to the 'read a 
  149.  
  150. one' case for each program step. These steps are shown in the 
  151.  
  152. window labeled SOURCE LISTING on the right side. the END button 
  153.  
  154. is a special case; it is only used to enter a step in which the 
  155.  
  156. Turing program is to terminate.
  157.  
  158.      Returning to the MODE box we can cycle through the other 
  159.  
  160. functions. These appear within the window and are selected by 
  161.  
  162. pressing the OK button. The modes are Trace, Input, Tape, Run, 
  163.  
  164. Edit, Print, Load, Save, Exit, Clear and Erase.
  165.  
  166.  
  167.      Trace runs an existing program and prints a step-by-step 
  168.  
  169.        trace of each instruction executed to an attached printer.
  170.  
  171.  
  172.      Input allows a new program to entered, as described above.
  173.  
  174.  
  175.      Tape is for setting initial conditions on the tape. This is 
  176.  
  177.        done by clicking on the boxes on the tape. The 
  178.  
  179.        values will alternate between zero and one. The tape 
  180.  
  181.        can be scrolled by using the long left- and right-pointing 
  182.  
  183.        arrows at the bottom sides of the screen.
  184.  
  185.  
  186.      Run starts the program. Execution can be stopped at any time 
  187.  
  188.         by clicking the left button. The tape can also be modified 
  189.  
  190.         after the program is stopped in this mode without going back 
  191.  
  192.         to the tape mode. Clicking on OK again will restart the 
  193.  
  194.         program with the new setup. In addition the Turbo box can 
  195.  
  196.         be clicked before starting the program to have it run in 
  197.  
  198.         an accelerated mode without sound effects.
  199.  
  200.  
  201.      Edit allows an existing program to be modified. To use edit 
  202.  
  203.        mode select this mode and click on the JUMP arrows until 
  204.  
  205.        the step you wish to edit is in the step window. Then 
  206.  
  207.        click inside the STEP box and that line will be displayed 
  208.  
  209.        in the source window. It is necessary to replace all six 
  210.  
  211.        parts of information for the step during an edit. Use 
  212.  
  213.        the same techniques as for entering a step originally. 
  214.  
  215.        If an existing program needs more steps added INPUT 
  216.  
  217.        mode can also be used. New steps will automatically be 
  218.  
  219.        entered at the end.
  220.  
  221.  
  222.      Print will output a listing of the control program to the 
  223.  
  224.        printer.
  225.  
  226.  
  227.      Load and Save allow programs to be read from or written to 
  228.  
  229.        disk. The default extension for these programs is ".TUR".
  230.  
  231.  
  232.      Exit ends the simulation and returns you to the desktop.
  233.  
  234.  
  235.      Clear erase the current program from memory.
  236.  
  237.  
  238.      Erase clears the tape back to all zeros.
  239.  
  240.  
  241.      When the program first starts, the SOURCE LISTING window
  242.  
  243. will give some initial help. In addition a series of prompts are
  244.  
  245. shown along the bottom as the program is used. The two arrows
  246.  
  247. above and below the Listing window allow the source to be
  248.  
  249. scrolled.
  250.  
  251.  
  252.      Each line of the program is represented by three symbols. 
  253.  
  254. The step number is followed by an arrow indicating the direction 
  255.  
  256. the tape will move, then a zero or one to show what will be 
  257.  
  258. written and lastly the step number to jump to. This sequence is 
  259.  
  260. on the left for the 'read a zero' case and on the right for the 
  261.  
  262. 'read a one'. On a printed listing the left and right arrows are 
  263.  
  264. replaced by plus and minus one. The box labeled END generates a 
  265.  
  266. cross in a circle. This special symbol is placed to indicate that 
  267.  
  268. the control program is not to proceed past this step.
  269.  
  270.  
  271.  
  272.                              Entering a program
  273.  
  274.      To enter a typical program step click on MODE until the word 
  275.  
  276. INPUT appears, then click on OK. Now select one MOVE button, one 
  277.  
  278. WRITE button and use JUMP arrows to scroll the window to the step 
  279.  
  280. required. Click on STEP to enter this as well. If everything is 
  281.  
  282. to your liking click on DO and the cursor will move to the right 
  283.  
  284. side of the source window for the other half of the program step. 
  285.  
  286. Before pressing DO any value can be changed by clicking on the 
  287.  
  288. desired replacement button. The three values needed for each half 
  289.  
  290. of the program can be entered in any order.
  291.  
  292.      When the program has been entered click on MODE until TAPE 
  293.   
  294. appears in the window, the press OK. Now click on the tape to set 
  295.  
  296. or clear ones. The tape can be scrolled to enter more data, if 
  297.  
  298. needed. The box labeled MARK shows the position of the read/write 
  299.  
  300. head over the tape. For faster positioning, this box can be clicked
  301.  
  302. on. Enter a number within the indicated limits and the pointer will
  303.  
  304. jump to that spot. While a true Turing machine should have an 
  305.  
  306. infinite tape, I have restricted this to several thousand 
  307.  
  308. positions as a practical limit. If the tape progresses to either end 
  309.  
  310. the program will stop.
  311.  
  312.      When all is set, change the mode to RUN or TRACE and press 
  313.  
  314. OK. Also set Turbo if desired; this will elimante the sound
  315.  
  316. effects and speed up the execution considerably. The machine
  317.  
  318. will immediately begin executing your program. The source window
  319.  
  320. will show the current step being executed and a small arrow will
  321.  
  322. indicate which case (zero or one) is being taken. The program
  323.  
  324. can be stopped at any time by pressing the left mouse button.
  325.  
  326.      The program can be reviewed by clicking in the SOURCE 
  327.  
  328. LISTING window. The first twelve steps will be shown. Use the 
  329.  
  330. small arrows above and below the window to scroll the listing.
  331.  
  332.  
  333.                         Sample Turing Programs
  334.  
  335.      There are some sample programs in the package. The first, 
  336.  
  337. NOT.TUR changes every one to a zero and vice versa. The second, 
  338.  
  339. ADD.TUR, adds two numbers together. The numbers are represented
  340.  
  341. on the tape by a series of ones equal to the value of the first 
  342.  
  343. number, a zero, and then the next number represented by ones 
  344.  
  345. again. Start the program from the left side and it will combine 
  346.  
  347. the two numbers together by removing the zero between them.
  348.  
  349.      A more interesting program to try is to multiply two numbers 
  350.  
  351. together. The trick here is to treat multiplication as successive 
  352.  
  353. addition. First write a routine which copies the left hand string 
  354.  
  355. to the end of the right one. Then use this subroutine in a longer 
  356.  
  357. program which copies the left number as many times as there are 
  358.  
  359. ones in the original string.
  360.  
  361.      Another interesting class of Turing programs are called Busy 
  362.  
  363. Beavers. These programs attempt to write the longest string of 
  364.  
  365. successive ones to a tape initially filled with zeros before 
  366.  
  367. halting. This problem has been solved for Turing machines having 
  368.  
  369. up through four states. The longest five state Busy Beaver found 
  370.  
  371. to date generates 1915 ones before halting. The listings for all 
  372.  
  373. of these are included. In addition I include a Busy Beaver which 
  374.  
  375. spends much time moving to and fro, but which ends up by doing 
  376.  
  377. nothing. This class of programs are called Dizzy Beavers. Refer 
  378.  
  379. to the bibliography for the source of these Turing programs. 
  380.  
  381.      If you develop any interesting Turing programs, please post 
  382.  
  383. them on one of the public bulletin boards, for others to see.
  384.  
  385.  
  386.                            Bibliography
  387.  
  388.      For further reading on this subject you can consult the 
  389.  
  390. following references:
  391.  
  392.  
  393. Hopcroft, John E., "Turing Machines", Scientific American, May 
  394.  
  395. 1984, pp. 86-98.
  396.  
  397.  
  398. Malitz, Isaac, "The Turing Machine", Byte, November 1987, pp. 
  399.  
  400. 345-358.
  401.  
  402.  
  403. Dewdney, A.K., "Busy Beavers", The Armchair Universe, W.H. 
  404.  
  405. Freeman, New York, 1988, pp. 160-171.
  406.  
  407.  
  408. Turing, A., "On the Computable Numbers, with an Application to 
  409.  
  410. the Entschiedungsproblem", Proceedings of the London Mathematical 
  411.  
  412. Society, Series 2-42, 1936. pp. 230-265.
  413.  
  414.